package io.geekidea.springbootplus.system.service.impl;

import io.geekidea.springbootplus.system.entity.CarrierSchool;
import io.geekidea.springbootplus.system.mapper.CarrierSchoolMapper;
import io.geekidea.springbootplus.system.service.CarrierSchoolService;
import io.geekidea.springbootplus.system.param.CarrierSchoolPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
/**
 *  服务实现类
 *
 * @author miko
 * @since 2020-10-15
 */
@Slf4j
@Service
public class CarrierSchoolServiceImpl extends BaseServiceImpl<CarrierSchoolMapper, CarrierSchool> implements CarrierSchoolService {

    @Autowired
    private CarrierSchoolMapper carrierSchoolMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveCarrierSchool(CarrierSchool carrierSchool) throws Exception {
        return super.save(carrierSchool);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateCarrierSchool(CarrierSchool carrierSchool) throws Exception {
        return super.updateById(carrierSchool);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteCarrierSchool(Long id) throws Exception {
        return super.removeById(id);
    }


    @Override
    public List<CarrierSchool> getAllList(LambdaQueryWrapper<CarrierSchool> wrapper) throws Exception{
        return carrierSchoolMapper.selectList(wrapper);
    }



    @Override
    public Paging<CarrierSchool> getCarrierSchoolPageList(CarrierSchoolPageParam carrierSchoolPageParam) throws Exception {
        Page<CarrierSchool> page = new PageInfo<>(carrierSchoolPageParam, OrderItem.desc(getLambdaColumn(CarrierSchool::getCreateTime)));
        LambdaQueryWrapper<CarrierSchool> wrapper = new LambdaQueryWrapper<>();
        IPage<CarrierSchool> iPage = carrierSchoolMapper.selectPage(page, wrapper);
        return new Paging<CarrierSchool>(iPage);
    }

}
